#ifndef BOARD_H
#define BOARD_H

#include "Types.h"
#include "Bitboard.h"
using namespace Bitboards;

#define PIECEBB_SIZE 16

class Board {

private:
	Piece pieces[64];
	Bitboard piecesBB[PIECEBB_SIZE];
	Bitboard emptyBB;
	Bitboard occupiedBB;

public:
	Board();
	Board(Board & b);


	void Clear();
	void Clear(int square);
	void SetPiece(Piece piece, Square square);
	Piece GetPiece(Square square);
	void DoMove(Move move);
	void UndoMove(Move move, Piece piece, Piece cPiece);

	bool IsSquareEmpty(Square square);
	bool IsEqual(Board& b);

	int Evaluate();
	void DebugDisplay();
	char PieceToChar(Piece p);
	bool IsCheck(Color side);
	bool IsCheck(Square square, Color bySide);
};

// Slow custom implementation -  use intrinsec functions instead
inline bool slowBitScanForward(unsigned long* index, Bitboard mask)
{
	index = 0;
	while ((mask & 1)==0)
	{
		mask >>= 1;
		index++;
	}
	return mask != 0;
}

// Slow custom implementation -  use intrinsec functions instead
inline bool slowBitScanReverse(unsigned long* index, Bitboard mask)
{
	index = 0;
	while (mask > 1)
	{
		mask >>= 1;
		index++;
	}
	return mask == 1;
}


#endif